package org.fireflow2.designer.eclipse.actions;

import org.eclipse.gef.ContextMenuProvider;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.GEFActionConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.actions.ActionFactory;
import org.fireflow2.designer.eclipse.actions.AddDataFieldAction;
import org.fireflow2.designer.eclipse.actions.AddFormTaskAction;
import org.fireflow2.designer.eclipse.actions.AddSubflowTaskAction;
import org.fireflow2.designer.eclipse.actions.AddTaskReferenceAction;
import org.fireflow2.designer.eclipse.actions.AddToolTaskAction;

public class DesignPanelContextMenuProvider extends ContextMenuProvider {
	private ActionRegistry actionRegistry;
	
	public DesignPanelContextMenuProvider(EditPartViewer viewer, ActionRegistry registry) {
        super(viewer);
        actionRegistry = registry;
	}
	
	@Override
	public void buildContextMenu(IMenuManager menu) {
		// TODO Auto-generated method stub
        GEFActionConstants.addStandardActionGroups(menu);
        // Add actions to the menu
        
        menu.appendToGroup(GEFActionConstants.GROUP_UNDO,getAction(ActionFactory.UNDO.getId()));
        menu.appendToGroup(GEFActionConstants.GROUP_UNDO, getAction(ActionFactory.REDO.getId()));
        
//        menu.appendToGroup(GEFActionConstants.GROUP_ADD, getAction(AddFormTaskAction.ID));
//        menu.appendToGroup(GEFActionConstants.GROUP_ADD, getAction(AddToolTaskAction.ID));
//        menu.appendToGroup(GEFActionConstants.GROUP_ADD, getAction(AddSubflowTaskAction.ID));
//        
//        menu.appendToGroup(GEFActionConstants.GROUP_ADD, getAction(AddTaskReferenceAction.ID));
//        
        
        menu.appendToGroup(GEFActionConstants.GROUP_EDIT, getAction(ActionFactory.DELETE.getId()));
        menu.appendToGroup(GEFActionConstants.GROUP_VIEW, getAction(ShowPropertyViewAction.ID));
        
        menu.appendToGroup(GEFActionConstants.GROUP_ADD, getAction(AddDataFieldAction.ID));
        menu.appendToGroup(GEFActionConstants.GROUP_ADD, getAction(AddResourceDefAction.ID));

	}
	
    private IAction getAction(String actionId) {
    	//ActionRegistry是WorkflowProcessDesignerPanel.createActions()方法统一创建的
    	//在WorkflowProcessContentOutlinePage.init中，该ActionRegistry被获取到
        return actionRegistry.getAction(actionId);
    }
}
